﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;

namespace ClassLibrary1_DAL
{
    public static class DB
        {
            public static string connectionString = @"Server=TRUONGNLNSE6132\SQLEXPRESS; Database = testSkill_data; Trusted_Connection=True";
            private static SqlConnection sc = new SqlConnection(connectionString);
            private static SqlCommand scmd;
            public static void SetQuery(string queryString)
            {
                scmd = new SqlCommand(queryString, sc);
            }
            public static void AddParameters(string key, object value)
            {
                scmd.Parameters.AddWithValue(key,value);
            }
            public static int ExeNoneQuery()
            {
                sc.Open();
                int q = scmd.ExecuteNonQuery();
                sc.Close();
                return q;
            }
            public static List<List<object>> ExeQuery()
            {
                sc.Open();
                SqlDataReader sdr = scmd.ExecuteReader();
                List<List<object>> result = new List<List<object>>();
                if (sdr.HasRows)
                {
                    while (sdr.Read())
                    {
                        List<object> lo = new List<object>();
                        for (int i = 0; i < sdr.FieldCount; i++)
                        {
                            lo.Add(sdr[i]);
                        }
                        result.Add(lo);
                    }

                }
                sc.Close();
                return result;
            }




        }

}
